/*
 * RTSAI - Real-Time Strategy engine for AI research
 * Copyright(C) 2006 DIMAp-UFRN, licensed under LGPL
 *
 * UnitState header ( UnitState.h )
 * Author: Diogo Leite Reboucas
 */

#ifndef UNIT_STATE_H_
#define UNIT_STATE_H_

// INCLUDES -------------------------------------------------------------------
#include "Common.h"


// CLASS ----------------------------------------------------------------------
/*! This class implements abstract unit states for the game */
class UnitState
{
    // PUBLIC METHODS =========================================================
    public:
        // Constructors -------------------------------------------------------
        UnitState ( Unit *u = NULL ) : unit ( u ) { /* Empty */ };

        // virtual (defined by subclasses or scripts ) ------------------------
        /*! Method called on each game loop iteration. */
        virtual Action* act () { return NULL; }

        /*! Method called when a unit is getting to this state. */
        virtual void on_enter () { /* Empty */ }

        /*! Method called before the unit changes to another state. */
        virtual void on_exit () { /* Empty */ }

        /*! Specify how the state will react to a given event.
         * If a new state is returned, the unit changes its state to the
         * returned one.
         */
        virtual UnitState* react_to_event ( const string &event_name,
                                            GameEventData *data )
        {
            return NULL;
        };

        /*! Called when one or more messages are received by the unit */
        virtual void on_message ( MailBox &msgs ) { /* Empty */ }

        // void ---------------------------------------------------------------
        /*! Register the state to listen to a given event type. */
        void listen_to ( GameEvent *event );

        // Destructor
        virtual ~UnitState ();

    // ATTRIBUTES =============================================================
    public:
        /// Unit executing this state
        Unit *unit;

    private:
        /// Events that this state is listening to
        EventList listening_to;
};

#endif
